/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p></p>
 * <p>Powered by webrx On 2023-04-26 14:46:18</p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
@Configuration
public class MybatisPlusConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        //interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));

        //DbType.MYSQL 代表数据库类型
        PaginationInnerInterceptor pi = new PaginationInnerInterceptor(DbType.MYSQL);
        //此参数如果不设置，默认使用false,true 代表当前页合理设置，如果大于总页数，就显示第1页
        pi.setOverflow(false);
        interceptor.addInnerInterceptor(pi);

        //乐观锁插件
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }
}
